package com.itdao.dp.strategy.account2;

import com.itdao.dp.strategy.account2.behavior2.impl.EmailLoginServiceImpl;
import com.itdao.dp.strategy.account2.behavior2.impl.MobileLoginServiceImpl;
import com.itdao.dp.strategy.account2.dto.LoginDto;
import com.itdao.dp.strategy.account2.holder2.AccountService;
import com.itdao.dp.strategy.account2.holder2.AccountType;
import com.itdao.dp.strategy.account2.holder2.EmailAccountService;
import com.itdao.dp.strategy.account2.holder2.MobileAccountService;

import java.util.HashMap;
import java.util.Map;

public class Application {
    /**
     * 这里使用一个Map来存放账户类型和具体的账户服务实现类之间的映射关系
     */
    private static Map<String, AccountService> accountHolderMap = new HashMap<String, AccountService>() {{
        put(AccountType.EMAIL.name(), new EmailAccountService(new EmailLoginServiceImpl()));
        put(AccountType.MOBILE.name(), new MobileAccountService(new MobileLoginServiceImpl()));
    }};

    public static void main(String[] args) {
        // 选择账户类型
        String accountType = AccountType.EMAIL.name();
        // 登录测试
        testLogin(accountType);
    }

    /**
     * 测试登录
     *
     * @param accountType 账户类型
     */
    private static void testLogin(String accountType) {
        // 根据账户类型，来调用相应的账户服务
        AccountService accountService = accountHolderMap.get(accountType);
        LoginDto loginDto = new LoginDto("admin", "123456");
        accountService.login(loginDto);
    }
}
